﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Hive.Core
{
    public class Counter
    {
        public int Times { get; set; }
        public int Average 
        { 
            get
            {
                return (int)(Total / Times);
            }
        }
        public long Total { get; set; }
    }   
    public class Perf
    {
        public static Dictionary<string, Counter> sections = new Dictionary<string, Counter>();
        static Dictionary<string, Stopwatch> current = new Dictionary<string, Stopwatch>();
        public static void Start(string section)
        {
            current[section] = new Stopwatch();
            current[section].Start();
        }

        public static void End(string section)
        {
            if (!sections.ContainsKey(section))
                sections.Add(section, new Counter());
            
            sections[section].Total += current[section].ElapsedMilliseconds;
            sections[section].Times++;
        }

    }
}
